import 'dart:io';

main(){
  print('程序开始，执行main入口函数');
  Future(()async{
    //1.登录成功，返回token
    String token = await login(username: 'admin', password: '123456');
    print('登录成功，返回token$token');
    //2.根据token 获取用户信息
    Map userInfo = await getUserInfo(token: token);
    print('根据token 获取用户信息$userInfo');
    //3.保存用户信息
    await saveUserInfo(userInfo: userInfo);
    print('保存用户信息成功');
  }); 
  print('程序结束,执行main入口函数,不能阻塞的代码');

}
//1.登录成功，返回token
Future<String> login({required String username,required String password}) {
return  Future((){
sleep(Duration(seconds: 2));
return '123456';

});

}

//2.根据token 获取用户信息
Future<Map> getUserInfo({required String token}) {
  return Future((){
    sleep(Duration(seconds: 2));
    return {'name':'张三','age':18};

  });
}


//3.保存用户信息
Future<void> saveUserInfo({required Map userInfo}) {
  return Future((){
    sleep(Duration(seconds: 2));
    print('保存用户信息$userInfo');
  });
}
